/*
* Author: John Ryland (jryland), jryland@xiaofrog.com
* Company: InvertedLogic
*/
#ifndef DEBUG_MEMORY_H
#define DEBUG_MEMORY_H
class DebugMemory {
public:
// Public API
static void showMemoryLeaks();
static void showMemoryAllocations();
static void logMemoryAllocations(int level);
// Internal implementation function
static void *addLog(int t, void *p, unsigned int num, unsigned int size, const char *file, int line);
};
#endif // DEBUG_MEMORY_H
#ifdef DEBUG // Logging enabled in debug builds
#ifndef _DEBUG_MEMORY_OFF_ // Avoid recursion
#define addLogWrapper(a,b,c,d) DebugMemory::addLog(a, b, c, d, __FILE__, __LINE__)
#define calloc(num,siz) addLogWrapper(1, 0, num, siz)
#define valloc(siz) addLogWrapper(2, 0, 1, siz)
#define realloc(ptr,siz) addLogWrapper(3, ptr, 1, siz)
#define reallocf(ptr,siz) addLogWrapper(4, ptr, 1, siz)
#define malloc(siz) addLogWrapper(5, 0, 1, siz)
#define free(ptr) addLogWrapper(10, ptr, 0, 0), (void)0
#define new (addLogWrapper(0, 0, 0, 0), false) ? 0 : new
#define delete (addLogWrapper(0, 0, 0, 0), false) ? (void)0 : delete
#endif // _DEBUG_MEMORY_OFF_
#endif // DEBUG